package litcode;

/**
 * @Description:   给定数字将其翻转
 * @Author: sult
 * @CreateDate: 2019/2/20 18:08
 */
public class numberFlip {

    public static void main(String[] args) {
        System.out.println(reverseInteger(9000));
        System.out.println(reverseInteger(506098));
    }


    /**
     * @param number: A 3-digit number.
     * @return: Reversed number.
     */
    public static int reverseInteger(int number) {

        char[] val= String.valueOf(number).toCharArray();
        char[]  newVal = new char[val.length];
        int j=0;
        char pre='0';
        for(int i=val.length-1;i>=0;i--){
            if(pre==val[i]){
                continue;
            }else{
                newVal[j]=val[i];
                pre='a';
            }
            j++;
        }
        String v=new String(newVal);
        return Integer.parseInt(v.trim());
    }
}
